using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Mvc.Mailer;
using System.Net.Mail;
using viBook.Common;
using viBook.Models;

namespace viBook.Mailers
{ 
    public class UserMailer : MailerBase, IUserMailer
    {
		public UserMailer():
			base()
		{
			MasterName="_Layout";
		}


        public virtual MailMessage Activate(User user)
		{
			var mailMessage = new MailMessage{Subject = "Activate your account at ViBook"};
            StringBuilder link = new StringBuilder(HttpContext.Current.Request.Url.Scheme);
            link.Append("://");
            link.Append(HttpContext.Current.Request.Url.Authority);
            link.Append(Constant.ActivatePath);
            link.Append("?userid=");
            link.Append(user.Id);
            link.Append("&code=");
            link.Append(user.ValidationCode);
			mailMessage.To.Add(user.Email);
            ViewBag.Name = user.Username;
			ViewBag.ActivateLink = link.ToString();
			PopulateBody(mailMessage, "Activate");

			return mailMessage;
		}

		public virtual MailMessage ResetPassword(User user)
		{
			var mailMessage = new MailMessage{Subject = "Reset your account password at ViBook"};
            StringBuilder link = new StringBuilder(HttpContext.Current.Request.Url.Scheme);
            link.Append("://");
            link.Append(HttpContext.Current.Request.Url.Authority);
            link.Append(Constant.ResetPasswordPath);
            link.Append("?userid=");
            link.Append(user.Id);
            link.Append("&code=");
            link.Append(user.ValidationCode);
            mailMessage.To.Add(user.Email);
            ViewBag.Name = user.Username;
            ViewBag.ResetPasswordLink = link.ToString();

			PopulateBody(mailMessage, "ResetPassword");

			return mailMessage;
		}

		
	}
}